package xmlService;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import beans.CotizacionBean;
import beans.FinanciacionBean;
import beans.PagoContadoBean;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class CotizacionXmlService {

	public static void main(String[] args) {
		CotizacionBean sc = cargarCotizacion();
		
	}

	public static CotizacionBean cargarCotizacion()
	{
		CotizacionBean c = null;
		
		XStream xstream = new XStream( new DomDriver());
		xstream.autodetectAnnotations(true);  
		
		xstream.alias("Cotizacion", CotizacionBean.class);
		xstream.alias("PagoContado", PagoContadoBean.class);
		xstream.alias("Financiacion", FinanciacionBean.class);
		FileInputStream fis;
		try {
			fis = new FileInputStream("src/XML/Cotizacion.xml");
			c = (CotizacionBean) xstream.fromXML(fis);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return c;				
	}
	
	public static void  guardarCotizacioin(CotizacionBean c)
	{
		
		XStream xstream = new XStream( new DomDriver());
		xstream.autodetectAnnotations(true);  
		
		xstream.alias("Cotizacion", CotizacionBean.class);
		xstream.alias("PagoContado", PagoContadoBean.class);
		xstream.alias("Financiacion", FinanciacionBean.class);
		FileOutputStream fos;
		try {
			fos = new FileOutputStream("src/XML/CotizacionGenerada.xml");
			String s = xstream.toXML(c);
			fos.write(s.getBytes());
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
				
	}
	
}
